package com.zfl;

public class InvertTree {
    public TreeNode invertTree(TreeNode root) {
        if (root == null) {
            return null;
        }

        preorder(root);
        return root;
    }

    private void preorder(TreeNode root) {
        if (root == null)
            return;
        TreeNode temp = root.left;
        root.left = root.right;
        root.right = temp;
        this.preorder(root.left);
        this.preorder(root.right);
    }
}
